#include "CfgParsers.h"
#include <iostream>
#include <string>

namespace CfgParsers
{

namespace Engine
{
CfgParser::CfgParser(ParseData &data)
	: data(data)
{
}

CfgParser::~CfgParser()
{
}

void CfgParser::run(const TCODParserPtr &cfg_parser, const std::string &cfg_path, ParseData &data)
{
	auto type = cfg_parser->newStructure("engine_cfg_type");
	type->addProperty("width", TCOD_TYPE_INT, true);
	type->addProperty("height", TCOD_TYPE_INT, true);
	type->addProperty("near_clip", TCOD_TYPE_FLOAT, false);
	type->addProperty("far_clip", TCOD_TYPE_FLOAT, false);
	cfg_parser->run(cfg_path.c_str(), new CfgParser(data));
}

bool CfgParser::parserNewStruct(TCODParser *parser,const TCODParserStruct *str,const char *name)
{
	/*std::string str_name = str->getName();
	std::cout << str_name << std::endl;
	if(str_name == "engine_cfg_type")
	{
	}*/
	return true;
}

bool CfgParser::parserFlag(TCODParser *parser,const char *name)
{
	//std::string str_name = name;
	return true;
}

bool CfgParser::parserProperty(TCODParser *parser,const char *name, TCOD_value_type_t vtype, TCOD_value_t value)
{
	std::string str_name = name;
	if(str_name == "width")
		data.width = value.i;
	else if(str_name == "height")
		data.height = value.i;
	else if(str_name == "near_clip")
		data.near_clip = value.f;
	else if(str_name == "far_clip")
		data.far_clip = value.f;

	return true;
}

bool CfgParser::parserEndStruct(TCODParser *parser,const TCODParserStruct *str, const char *name)
{
	//std::string str_name = str->getName();
	return true;
}

void CfgParser::error(const char *msg)
{
	std::cout << "ENGINE CFG PARSER ERROR: " << msg << std::endl;
}

}

}